Text on a GBA is a row of small sprites, one per character, so every word you draw spends from the same budget as everything else on screen.
A modern computer has a text engine: you hand it a sentence and it paints letters. The GBA has no such thing. It only knows how to draw tiles and sprites. So when you draw the word HELLO, the engine builds five small sprites, one for each letter, and lines them up. From then on they are ordinary sprites. They count against the 128 sprites the hardware can draw in one frame, and against the sprite palette banks, like any other sprite. Budgets lists both.
Three consequences follow, and they explain most of this page:
SCORE 99999 uses about eleven.draw_text call keeps room for 12 letter sprites (the number every game starts with: raise Sprites in one drawn thing under Engine limits in Project Settings, up to 32, to show longer lines), and a longer string is cut off after that. For longer text, split it across two or more calls, one per line, or use \n (see Several lines).You give draw_text a position and a string. A string is text in a program: letters and symbols between double quotes, like "OW!".
// Draw event of an enemy that has just been hit
draw_text(x, y - 16, "OW!");Call it from a Draw event (see Drawing and the draw order). It has to be repeated every frame, because the text is shown only while the call keeps being made. Repeating the same words at the same spot is cheap. The engine reuses last frame's sprites, and only rebuilds them when the string, the position or the alignment changes.
There are two drawing functions, plain and warped (scaled and rotated), and they draw in two places, which the event decides:
| In a Draw event (scrolls with the camera) | In a Draw GUI event (fixed to the screen) | |
|---|---|---|
| plain | draw_text | draw_text |
| scaled and rotated | draw_text_warped | draw_text_warped |
In a Draw event, text is about a place: a damage number above an enemy, a name over a character. In a Draw GUI event it is for a score or a health readout that stays put while the room scrolls, and it always draws in front of the whole world. It is the same call in both: no second name to learn. To fix text to the screen from some other event, use draw_text_anchored.
The warped forms take three more values, xscale, yscale and angle, so a title can spin or a score can pop. Angles are in degrees, 0 is east, and turning a bigger angle turns counterclockwise. A negative scale mirrors the whole string. All the letters share one affine matrix, one of the hardware's 32. A warped call with scale 1 and angle 0 needs no matrix at all. If all 32 are already in use somewhere else, the text is still drawn, just unwarped for that frame.
Text can also lean, the way italic writing does. draw_text_sheared takes the warped call's six values and two more, xshear and yshear, and does the scaling, the turning and the leaning in one call. It scrolls with the camera and has no screen-fixed form.
Write \n inside the string where a new line should start, and one call draws several lines:
// Draw GUI event
draw_text(8, 8, "GAME OVER\nPRESS START");x and sits one line lower, the height of a letter of the current font (8 pixels for the default font). The y you give is the middle of the first line, exactly as for one line.ALIGN_CENTER every line is centered on x; with ALIGN_RIGHT every line ends at x.draw_text_warped and draw_text_sheared scale, turn and lean all the lines together, around the spot (x, y) marks on the first line."one\n\ntwo" leaves a blank line between the two.draw_text_3d and its relatives curve a single line, so they draw the text up to the first \n and leave the rest out. Draw each line with its own call.A font is an asset in your project, like a sprite. font_set(f) chooses which font every text call uses from then on, until you change it. It is a setting you leave switched, not something you pass to each call. Calling it once in a room's setup is usual.
You do not have to call it. If a project draws text and never picks a font, the game uses a default font: plain letters, numbers and punctuation, each 8 pixels wide and 8 tall.
The default font is a real font in your project. The first time you build a game that draws text, Gbabel copies it into your project as assets/fonts/font_default and lists it with your other fonts. From then on it is yours. Open it in the Paint tab and change it like any font you made yourself: the Font Wizard walks you through its letters one at a time. The game starts with it selected, so text drawn before any font_set call looks the way you drew it.
Two things to know:
font_default. That name is how the game finds its starting font. If you rename it, the next build adds a fresh copy.font_default you changed. If you delete the picture, the next build puts the original back.A project that never draws text never gets a font_default, and nothing is added to its game.
What a font costs:
text_align(align) decides what the x you give means. It takes one of ALIGN_LEFT (the default: x is where the text starts), ALIGN_CENTER (x is the middle of the text) or ALIGN_RIGHT (x is where the text ends). Like font_set, it stays in effect until changed. For warped text the same point is also the center that the turning and scaling happens around.
Here is a readout that stays in the top-right corner of the screen while the room scrolls. ALIGN_RIGHT makes x the place where the text ends, so the word lines up against the right edge:
// Draw GUI event of an object that is always in the room
text_align(ALIGN_RIGHT);
draw_text(236, 4, "SCORE");Text follows the same rules as any sprite. Its layer and order come from the instance drawing it: bg_priority first, then depth. A text call at a higher depth draws behind a sprite at a lower one. Only a draw call in a Draw GUI event is different: it ignores bg_priority and sits on the front-most layer.
| Entry | What it is |
|---|---|
draw_text | plain text, in the world (in a Draw event) or on the screen (in a Draw GUI event) |
draw_text_warped | scaled and rotated text, in the world or on the screen the same way |
draw_text_sheared | scaled, rotated and leaning text, in the world |
font_set | choose the font (the default one is font_default, a font in your project) |
text_align | choose the alignment |
Turning a number into text, so a score can be drawn, is done with string. Joining pieces of text together is string_join.